﻿<?php
$serverip=$_POST['serverip'];
$port=$_POST['port'];
$mount=$_POST['mount'];
$password=$_POST['password'];
$ordertarif=$_POST['tarif'];
switch($ordertarif)
{
    case 'Lite': $slots=50;$quality=64; break;
    case 'Lite+': $slots=100;$quality=64; break;
    case 'Medium': $slots=50;$quality=128; break;
    case 'Medium+': $slots=100;$quality=128; break;
    case 'Professional': $slots=50;$quality=192; break;
    case 'Professional+': $slots=100;$quality=192; break;
    default:
        $tarif_array=explode("(",$ordertarif);
        $tarif_name=$tarif_array[0];
        $slots_array=explode(" ",$tarif_name);
        $slots=$slots_array[1];
        $quality_array=explode(" ",$tarif_array[1]);
        $quality=$quality_array[0];
        break;
}
function post_content ($url,$postdata) {
  $uagent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";

  $ch = curl_init( $url );
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_setopt($ch, CURLOPT_USERAGENT, $uagent);  // useragent
  curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  $content = curl_exec( $ch );
  curl_close( $ch );
  return $content;
}
function ckeckLatin($str)
{
  if (!preg_match("/^[a-zA-Z0-9]+$/i", $str)) {
    return 0;
  }
  else
  {
    return 1;
  }
}
$mount_tmp=substr($mount,1);
if(ckeckLatin($mount_tmp)&&$mount{0}=='/')
{

  $url='http://'.$serverip.'/panel/usericecastconf_create.php';
  $postdata='username=user'.$port.'&port='.$port.'&mount='.$mount.'&password='.$password.'&listeners='.$slots;
  $data= post_content($url,$postdata);
  echo $data;
}
else
{
  echo 'Конфиг не создан! Не верный маунт!';
}
?>